package com.fbs.job.core.biz.client;

import com.fbs.job.core.biz.ExecutorBiz;
import com.fbs.job.core.biz.model.LogParam;
import com.fbs.job.core.biz.model.LogResult;
import com.fbs.job.core.biz.model.TriggerParam;
import com.fbs.job.core.model.ResultT;
import com.fbs.job.core.util.FbsJobRemotingUtil;

public class ExecutorBizClient implements ExecutorBiz {
    private String addressUrl ;
    private String accessToken;
    private int timeout = 3;

    public ExecutorBizClient(String addressUrl, String accessToken) {
        this.addressUrl = addressUrl;
        this.accessToken = accessToken;

        // valid
        if (!this.addressUrl.endsWith("/")) {
            this.addressUrl = this.addressUrl + "/";
        }
    }

    @Override
    public ResultT<String> beat() {
        return FbsJobRemotingUtil.postBody(addressUrl+"beat", accessToken, timeout, "", String.class);
    }

    @Override
    public ResultT<String> run(TriggerParam triggerParam) {
        return FbsJobRemotingUtil.postBody(addressUrl + "run", accessToken, timeout, triggerParam, String.class);
    }


    @Override
    public ResultT<LogResult> log(LogParam logParam) {
        return FbsJobRemotingUtil.postBody(addressUrl + "log", accessToken, timeout, logParam, LogResult.class);
    }
}
